public class Josepfu {
    public static void main(String[] args) {
        CircleLinked circleLinked = new CircleLinked();
        circleLinked.add(5);
        circleLinked.show();

    }
}

class CircleLinked{
    private Boy first = null;

    public void add(int num){
        //判断是否错误
        if (num<1){
            System.out.println("num is error");
            return;
        }

        Boy curBoy = null;
        for (int i=1;i<=num;i++){
            Boy boy = new Boy(i);
            if (i==1){
                first = boy;
                first.setNext(first);//构成环
                curBoy = first;
            }
            else {
                curBoy.setNext(boy);
                boy.setNext(first);
                curBoy = boy;
            }
        }
    }

    public void show(){
        if (first==null){
            System.out.println("boy is null");
            return;
        }
        Boy boy = first;
        while (true){
            System.out.println("boy no is "+boy.getNo());
            if (boy.getNext()==first){
               return;
            }
            boy = boy.getNext();
        }
    }
}

class Boy{
    private int no;
    private Boy next;

    public Boy(int no) {
        this.no = no;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public Boy getNext() {
        return next;
    }

    public void setNext(Boy next) {
        this.next = next;
    }
}
